package com.tzkyzj.tiremanagersystem.ui;

import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;

import androidx.appcompat.app.AppCompatActivity;

import com.tzkyzj.tiremanagersystem.MyApplication;

public class SplashActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // 不需要布局，直接检查登录状态
        checkLoginStatus();
    }

    private void checkLoginStatus() {
        MyApplication app = (MyApplication) getApplication();

        // 延迟一下，让启动画面显示一会儿
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                if (app.isUserLoggedIn()) {
                    // 已登录，跳转到主界面
                    startActivity(new Intent(SplashActivity.this, TireListActivity.class));
                } else {
                    // 未登录，跳转到登录界面
                    startActivity(new Intent(SplashActivity.this, LoginActivity.class));
                }
                finish();
            }
        }, 1000); // 1秒延迟
    }
}